package com.u.tool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.u.Repiar.RepairItem_info;
import com.u.character.Role;
import com.u.eventInfo.Event;
import com.u.eventInfo.EventInfo;

public class EvevntDetailUtil {
	
	public static Map<String,Object> getEventDetail(String event_id) {
		Map<String,Object> map = new HashMap<>();
		MysqlUtil db = new MysqlUtil();
		db.connection();
		String sql = "SELECT * FROM y_r.event where event_id='" + event_id + "'";
		List list = new ArrayList<>();
		list = db.query(Event.class, sql);
		Event event = (Event) list.get(0);
		sql = "SELECT * FROM y_r.eventinfo where event_id='" + event_id + "'";
		System.out.println(sql);
		db.connection();
		list = db.query(EventInfo.class, sql);
		EventInfo eventInfo = (EventInfo) list.get(0);
		String item_id = event.getItem_id();
		sql = "SELECT * FROM y_r.repair_item where item_id='"+ item_id +"'";
		System.out.println(sql);
		db.connection();
		list = db.query(RepairItem_info.class, sql);
		System.out.println(list.size());
		RepairItem_info info = (RepairItem_info) list.get(0);
		String[] repairer = info.getRepairer().split(",");
		StringBuilder sqlbuilder = new StringBuilder("select * from y_r.role where user_acc in (");
		for(int i=0;i<repairer.length;i++) {
			if(i==0) {
				sqlbuilder.append("'"+repairer[i]+"'");
			}else {
				sqlbuilder.append(",'"+repairer[i]+"'");
			}
		}
		sqlbuilder.append(")");
		sql = sqlbuilder.toString();
		db.connection();
		List<Role> role_list = db.query(Role.class, sql);
		map.put("eventInfo", eventInfo);
		map.put("event", event);
		map.put("item", info);
		map.put("roleList", role_list);
		return map;
	}
	
	
}
